#ifndef SWIPEDETECTOR_H
#define SWIPEDETECTOR_H

#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>

class SwipeDetector 
{
public:
    enum Direction { NONE, UP, DOWN, LEFT, RIGHT };

    SwipeDetector();
    ~SwipeDetector();

    Direction detectSwipe();// 检测滑动方向
    //获取坐标
    int getX() const { return DeltaX; }
    int getY() const { return DeltaY; }
    //设置坐标
    void setXY(int x, int y) { DeltaX = x; DeltaY = y; }
    //重置触摸状态
    void resetTouchState();

private:
    static const char* TOUCH_DEVICE;
    static const int SWIPE_THRESHOLD = 50;     // 滑动阈值(像素)
    static const long TIME_THRESHOLD = 300000; // 时间阈值(微秒，300ms)

    int fd;                // 设备文件描述符
    int startX, startY;    // 起始坐标
    int endX, endY;        // 结束坐标
    long startTime;        // 起始时间(微秒)
    int DeltaX, DeltaY;    // 记录坐标
    bool touchDown;        // 触摸状态标志
};

#endif // SWIPEDETECTOR_H
